home *** CD-ROM | disk | FTP | other *** search
- Path: newshost.lanl.gov!tanmoy
- From: tanmoy@qcd.lanl.gov (Tanmoy Bhattacharya)
- Newsgroups: comp.lang.c
- Subject: Re: problem with types
- Date: 12 Mar 1996 22:05:56 GMT
- Organization: Los Alamos National Laboratory
- Message-ID: <TANMOY.96Mar12150556@qcd.lanl.gov>
- References: <Do5Mu9.6nv@lut.ac.uk>
- NNTP-Posting-Host: qcd.lanl.gov
- Mime-Version: 1.0
- Content-Type: text
- In-reply-to: R.Sheikhan@lut.ac.uk's message of Tue, 12 Mar 1996 12:32:33 GMT
-
- In article <Do5Mu9.6nv@lut.ac.uk>
- R.Sheikhan@lut.ac.uk (R.Sheikhan) writes:
-
- R: Hi;
- R: When I use int to declare my variable type my programme works fine, but
- R: when I use long it doesn't work. Every thing looks ok but I just can't
- R: figure out why. I would appreciate any help.
- <snip>
- R: printf(" LCM is %ld\n", LCM_Array(Numbers));
-
- No declaration of LCM_Array is visible at this point, so the return
- value is assumed to be int. This is passed to printf which assumes it
- is a long (%ld). The former is your mistake (You should declare `long
- LCM_ARRAY();' at the top), the latter leads to undefined behaviour
- (i.e. the compiler can now do what it pleases with the code).
-
- <snip>
- R: LCM_Array(Array)
-
- No return type is defined here (i.e. you did not say `long
- LCM_Array(Array)': if you had, you still would have had a problem
- unless you declared it at the top, because previous implicit
- declaration above was `extern int LCM_Array();'), so it defaults to
- int.
-
- <snip>
- R: long loop_counter;
- <snip>
- R: return sofar;
-
- The variable sofar is converted to int and returned.
-
- Cheers
- Tanmoy
- --
- tanmoy@qcd.lanl.gov(128.165.23.46) DECNET: BETA::"tanmoy@lanl.gov"(1.218=1242)
- Tanmoy Bhattacharya O:T-8(MS B285)LANL,NM87545 H:#9,3000,Trinity Drive,NM87544
- Others see <gopher://yaleinfo.yale.edu:7700/00/Internet-People/internet-mail>,
- <http://alpha.acast.nova.edu/cgi-bin/inmgq.pl>or<ftp://csd4.csd.uwm.edu/pub/
- internetwork-mail-guide>. -- <http://nqcd.lanl.gov/people/tanmoy/tanmoy.html>
- fax: 1 (505) 665 3003 voice: 1 (505) 665 4733 [ Home: 1 (505) 662 5596 ]
-